﻿using System.Windows.Forms;

namespace ComputerVision.Common
{
    public class Utilities
    {
        public static bool IsFormOpen(Form form)
        {
            foreach (Form f in Application.OpenForms)
                if (f.Name.Equals(form.Name) && f.Text.Equals(form.Text))
                    return true;
            return false;
        }

        public static bool IsFormOpen(string formName)
        {
            foreach (Form f in Application.OpenForms)
                if (f.Name.Equals(formName))
                    return true;
            return false;
        }

        public static void ActiveForm(Form form)
        {
            foreach (Form f in Application.OpenForms)
                if (f.Name.Equals(form.Name) && f.Text.Equals(form.Text))
                {
                    f.Activate();
                    break;
                }
            form.Dispose();
        }

        public static void CloseOldForm(Form form)
        {
            foreach (Form f in Application.OpenForms)
                if (f.Name.Equals(form.Name) && f.Text.Equals(form.Text))
                {
                    f.Close();
                    break;
                }
        }

        public static void CloseOldFormByName(string formName)
        {
            foreach (Form f in Application.OpenForms)
                if (f.Name.Equals(formName))
                {
                    f.Close();
                    break;
                }
        }
    }
}